﻿using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration; 
using System.Web.Configuration; 

/// <summary>
/// Descripción breve de DataBase
/// </summary>
public class DataBase
{
    public static OleDbConnection GetConnection()
    {
        try
        {
            Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("~");
            string connection = rootWebConfig.ConnectionStrings.ConnectionStrings["CadCon"].ConnectionString.ToString();
            return new OleDbConnection(connection);
        }
        catch (Exception Ex) {
            throw Ex;
        }

    }

    public static OleDbConnection GetConnection(string p_CadCon)
    {
        try
        {
            string connection = p_CadCon;
            return new OleDbConnection(connection);
        }
        catch (Exception Ex) {
            throw Ex;
        }

    }

    public static DataSet ds(string select, string table)
    {

        OleDbConnection objConnection = GetConnection();
        OleDbCommand objCommand = new OleDbCommand(select, objConnection);
        OleDbDataAdapter da = new OleDbDataAdapter(objCommand);
        DataSet ds = new DataSet();
        objConnection.Open();

        try
        {

            da.Fill(ds, table);

        }

        
        catch (OleDbException Ex)
        {

            throw Ex;
        }
        finally
        {
            objConnection.Close();
        }
        return ds; 

    }

    public static DataTable dt(string select)
    {

        OleDbConnection objConnection = GetConnection();
        OleDbCommand objCommand = new OleDbCommand(select, objConnection);
        OleDbDataAdapter da = new OleDbDataAdapter(objCommand);
        DataTable dt = new DataTable();
        objConnection.Open();

        try
        {

            da.Fill(dt);

        }


        catch (OleDbException Ex)
        {

            throw Ex;
        }
        finally
        {
            objConnection.Close();
        }
        return dt;

    }

}
